package org.lanqiao.netctoss.controller.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.lanqiao.netctoss.entity.Admin;
import org.lanqiao.netctoss.entity.Adper;
import org.lanqiao.netctoss.entity.Permiss;
import org.lanqiao.netctoss.service.impl.AdminServiceImpl;
import org.lanqiao.netctoss.service.impl.AdperServiceImpl;
import org.lanqiao.netctoss.service.impl.PermissServiceImpl;

/**
 * Servlet implementation class UpdateAdminServlet
 */
public class DeleteAdminServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteAdminServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		//response.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("GBK");
		/*AdminBuss adminBuss = new AdminBussImpl();
		AdperBuss adperBuss = new AdperBussImpl();
		PermissBuss permissBuss = new PermissBussImpl();*/
		if(request.getParameter("modify")!=null){	
			String adm_no = request.getParameter("modify");
			/*List<Admin> la = adminBuss.selAdminByno(new Admin(Integer.parseInt(adm_no)));
			List<Adper> lp = adperBuss.selAdper(new Admin(Integer.parseInt(adm_no)));		
			List<Permiss> lper = permissBuss.selectPermiss();*/
			List<Admin> la = new AdminServiceImpl().selectAdminByno(new Admin(Integer.parseInt(adm_no)));
			List<Adper> lp = new AdperServiceImpl().selectAdper(new Admin(Integer.parseInt(adm_no)));
			List<Permiss> lper = new PermissServiceImpl().selectPermiss();
			HttpSession session  = request.getSession();
			session.setAttribute("la",la);
			session.setAttribute("lp",lp);
			session.setAttribute("lper",lper);
			RequestDispatcher rd =request.getRequestDispatcher("../view/admin/admin_modi.jsp");
			rd.forward(request, response);				
		}else{
			String adm_no = request.getParameter("delete");
			/*boolean b=adperBuss.deleteAdperByAno(new Admin(Integer.parseInt(adm_no)));
			boolean a=adminBuss.delAdmin(new Admin(Integer.parseInt(adm_no)));*/
			boolean b = new AdminServiceImpl().deleteAdperByAno(new Admin(Integer.parseInt(adm_no)));
			int a = new AdminServiceImpl().deleteAdmin(new Admin(Integer.parseInt(adm_no)));
			PrintWriter out = response.getWriter();
			out.print("<script>alert('删除成功!');window.location.href='../admin/AdminListServlet'</script>");			
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
